package schoolWord;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.SimpleTimeZone;

public class Main {
    public static void main(String[] args)  {
        //a.利用GregorianCalendar的get方法输出系统当前时间
        GregorianCalendar g = new GregorianCalendar();

        int year = g.get(GregorianCalendar.YEAR);
        int month = g.get(GregorianCalendar.MONTH)+1;
        int day = g.get(GregorianCalendar.DAY_OF_MONTH);
        int h = g.get(GregorianCalendar.HOUR_OF_DAY);
        int m = g.get(GregorianCalendar.MINUTE);
        int sec = g.get(GregorianCalendar.SECOND);

        String time = "北京时间：" + year + "年" + month + "月" + day + "日" + h + "时" + m + "分" + sec + "秒";
        System.out.println(time);

        //b.将毫秒值1653392360281转为指定的日期格式
        long millis = 1653392360281L;
        SimpleDateFormat  sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date(millis);
        String str = sdf.format(date);
        System.out.println(str);

        //d."2024-2-28" 到 ”2024-5-12“ 有多少天
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date3 = sdf1.parse("2024-2-28");
            Date date4 = sdf1.parse("2024-5-12");

            long millis1 = date4.getTime() - date3.getTime();

            long Days = millis1 / (24*60*60*1000);
            System.out.println(Days);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
